package com.qooco.watersystem.extensions.client_handlers;

import com.qooco.watersystem.extensions.CocktailExtension;
import com.qooco.watersystem.extensions.LastGameEndResponse;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class ReadyHandler extends BaseClientRequestHandler 
{
	@Override
	public void handleClientRequest(User user, ISFSObject arg1) {
		
		trace("ReadyHandler.handleClientRequest() " + user.getName());
		
		CocktailExtension gameExt = (CocktailExtension) getParentExtension();
		
		if (gameExt == null) trace("gameExt == null"); 
		
		if (user.isPlayer())
		{
			trace("user.isPlayer()"); 
			
			if (gameExt.getGameRoom().getSize().getUserCount() == 2)
				gameExt.startGame();
		}
		
		else
		{
			trace("user.isNotPlayer()"); 
			
			gameExt.updateSpectator(user);
			LastGameEndResponse endResponse = gameExt.getLastGameEndResponse();
			
			if (endResponse == null) trace("endResponse == null"); 
			
			if (endResponse != null)
				send(endResponse.getCmd(), endResponse.getParams(), user);
		}

	}

}
